home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / libhtml-parser-perl / examples / hlc < prev    next >
Encoding:
Text File  |  2008-04-04  |  547 b   |  21 lines

  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4. use HTML::Parser ();
  5.  
  6. HTML::Parser->new(start_h   => [ \&start_lc, "tokenpos, text" ],
  7.               end_h     => [ sub { print lc shift }, "text" ],
  8.                   default_h => [ sub { print shift }, "text" ],
  9.                  )
  10.     ->parse_file(shift) || die "Can't open file: $!\n";
  11.  
  12. sub start_lc {
  13.     my($tpos, $text) = @_;
  14.     for (my $i = 0; $i < @$tpos; $i += 2) {
  15.     next if $i && ($i/2) % 2 == 0;  # skip attribute values
  16.     $_ = lc $_ for substr($text, $tpos->[$i], $tpos->[$i+1]);
  17.     }
  18.     print $text;
  19. }
  20.  
  21.